// components/system/navbar/navbar.ts
Component({
  options: {
    multipleSlots: true,
    addGlobalClass: true
  },
  properties: {
    /** 是否返回按钮为黑色 */
    isBlack: {
      type: Boolean,
      value: true
    },
    extClass: {
      type: String,
      value: ''
    },
    /**  导航栏标题 */
    title: {
      type: String,
      value: ''
    },
    /** 是否展示返回按钮 */
    back: {
      type: Boolean,
      value: true
    },
    /** 是否抛出返回方法到父容器 */
    myBackFunc: {
      type: Boolean,
      value: false
    },
    /** 标题颜色 */
    titleColor: {
      type: String,
      value: 'var(--color-text-regular)'
    }
  },

  data: {
    statusBarHeight: getApp().globalData.systemInfo.statusBarHeight
  },

  lifetimes: {
    attached: function () {
      console.log()
    },
    detached: function () {}
  },
  methods: {
    toHome() {
      wx.reLaunch({
        url: '/pages/index/index'
      })
    },
    goBack() {
      const data = this.data
      if (data.myBackFunc) {
        this.triggerEvent('goBack')
      } else {
        wx.navigateBack({
          fail: function () {
            wx.switchTab({
              url: '/pages/index/index'
            })
          }
        })
      }
    },
    navigateToEveryWhere(event: any) {
      const url = event.currentTarget.dataset.url
      wx.navigateTo({
        url: url
      })
    }
  }
})
